package com.yingxin.yxerp.module.sys.service.runner;

import com.yingxin.yx.framework.commons.helper.ListHelper;
import com.yingxin.yxerp.module.common.BusinessTypeHelper;
import com.yingxin.yxerp.module.sys.entity.BusinessTypeSetting;
import com.yingxin.yxerp.module.sys.service.IBusinessTypeSettingService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

@Order(1000)
@Component
public class BusinessTypeApplicationRunner implements ApplicationRunner {

    private final IBusinessTypeSettingService businessTypeSettingService;

    public BusinessTypeApplicationRunner(IBusinessTypeSettingService businessTypeSettingService) {
        this.businessTypeSettingService = businessTypeSettingService;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<BusinessTypeSetting> list = businessTypeSettingService.list();
        BusinessTypeHelper.updateAll(ListHelper.toMap(BusinessTypeSetting::getCode, BusinessTypeSetting::getName, list));
        /*
        List<String> a = new ArrayList<>();
        for (BusinessType type : BusinessType.values()) {
            String t = map.get(type.getType());
            if (t == null) {
                a.add(type.getType());
            }
        }
        System.out.println(a.toArray());
         */
    }
}